﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SMS_Server_Manager.Controls
{
    public partial class SQDisplay : UserControl
    {
        private Bitmap bmp;

        public SQDisplay()
        {
            InitializeComponent();
            bmp = (Bitmap)this.BackgroundImage;
        }

        //private
        private int signal_quality = 0;
        //public
        public int SignalQuality
        {
            get { return signal_quality; }
            set
            {
                signal_quality = value;
                //Make a copy of bmp
                Bitmap temp_bmp = (Bitmap)bmp.Clone();
                int ISQ = 100 - signal_quality;
                for (int x = 0; x < temp_bmp.Width; x++)
                {
                    for (int y = 0; y < temp_bmp.Height / 2; y++)
                    {
                        Color pevcolour = bmp.GetPixel(x, y);
                        int red_dif = (int)((decimal)(pevcolour.G - pevcolour.R) * (decimal)ISQ) / 100;
                        int green_dif = (int)((decimal)(pevcolour.R - pevcolour.G) * (decimal)ISQ) / 100;
                        Color newcolour = Color.FromArgb(pevcolour.A, pevcolour.R + red_dif, pevcolour.G + green_dif, pevcolour.B);
                        temp_bmp.SetPixel(x, y, newcolour);
                    }
                }
                this.BackgroundImage = temp_bmp;
                this.Invalidate();
            }
        }

    }
}
